package com.sunrise.xdoc.view.store;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import com.sunrise.xdoc.entity.store.Kho;
import com.sunrise.xdoc.entity.store.PhieuNhapKho;
import com.sunrise.xdoc.service.IStoreService;
import com.sunrise.xdoc.view.AbstractView;

@ManagedBean
@SessionScoped
public class PhieuNhapKhoView extends AbstractView<PhieuNhapKho> {
	private static final long serialVersionUID = -7722311010661221726L;

	@ManagedProperty(value = "#{storeService}")
	private IStoreService storeService;

	private List<Kho> khos;

	@Override
	@PostConstruct
	protected void init() {
		super.init();
		khos = storeService.getAllKhos();
	}

	public Long getSelectedKhoId() {
		if (getEditedEntity() != null && getEditedEntity().getKho() != null) {
			return getEditedEntity().getKho().getId();
		}
		return null;
	}

	public void setSelectedKhoId(Long selectedKhoId) {
		for (Kho kho : khos) {
			if (selectedKhoId.equals(kho.getId())) {
				getEditedEntity().setKho(kho);
				break;
			}
		}
	}

	public List<Kho> getKhos() {
		return khos;
	}

	public void setKhos(List<Kho> khos) {
		this.khos = khos;
	}

	public IStoreService getStoreService() {
		return storeService;
	}

	public void setStoreService(IStoreService storeService) {
		this.storeService = storeService;
	}

	@Override
	protected String getDataModelBeanName() {
		return "phieuNhapKhoDataModel";
	}

	@Override
	protected String getDetailPanelViewId() {
		return "phieuNhapKhoDialogId";
	}

}
